package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Employee;
import com.zretc.entity.ResponseResult;
import com.zretc.entity.Salary;
import com.zretc.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/salary")
public class SalaryController {
    @Autowired
    private SalaryService salaryService;

    @RequestMapping("/get")
    public ResponseResult getByPage( String name){

        Map<String,Object> map=new HashMap<>();
        map.put("name",name);
        List<Salary> all = salaryService.findAll(map);
        return ResponseResult.ok("查询成功",all);
    }
    @PostMapping("/add")
    public ResponseResult add(@RequestBody Salary salary){

        int add = salaryService.addSalary(salary);
        if (add>0){
            return ResponseResult.ok("添加成功");
        }
        return ResponseResult.ok("添加失败");
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult deleta(@PathVariable Integer id){

        int delete = salaryService.delete(id);
        if (delete>0){
            return ResponseResult.ok("删除成功");
        }
        return ResponseResult.ok("删除失败");
    }

    @PutMapping("/update")
    public ResponseResult update(@RequestBody Salary salary){

        int update = salaryService.updata(salary);
        if (update>0){
            return ResponseResult.ok("修改成功");
        }
        return ResponseResult.ok("修改失败");
    }


}
